package com.xinggq.gateway.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.reactive.function.client.WebClient;

/**
 * WebClient配置类
 * 配置支持负载均衡的WebClient
 *
 * @author xinggq
 * @since 2023-10-20
 */
@Configuration
public class WebClientConfig {

    /**
     * 创建支持负载均衡的WebClient.Builder
     * 使用@LoadBalanced注解确保WebClient支持服务发现和负载均衡
     */
    @Bean
    @LoadBalanced
    @Primary
    public WebClient.Builder loadBalancedWebClientBuilder() {
        return WebClient.builder();
    }
}